package com.lingying.caiwudailikehudaun.mapper.gongShangNianJian;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
@Mapper
public interface GongShangNianJianMapper {

    /**
     * 查询已年检客户
     * 桑满 20210605
     * @param
     * @return
     */
    @Select({"<script>"+
            "select g.* from gongShangNianJian g where g.zuoZhangShenBaoId = #{zuoZhangShenBaoId} AND g.xianShiZhuangTai = 1"+
            "<if test=\" companyName != null and companyName != ''\">" +
            " and g.companyName LIKE CONCAT ('%',#{companyName},'%') " +
            "</if>" +
            "<if test=\" suoShuNainDu != null and suoShuNainDu != ''\">" +
            " and g.suoShuNainDu = #{suoShuNainDu} " +
            "</if>" +
            " ORDER BY createTime DESC LIMIT #{pages},#{limit}"+
            "</script>"}
    )
    List<Map<String,Object>> selectGongShangNianJian(Integer zuoZhangShenBaoId, String companyName, String suoShuNainDu, Integer pages, Integer limit);


    /**
     * 数据总条数，用于分页
     * 桑满20210605
     * @param companyName
     * @param suoShuNainDu
     * @return
     */
    @Select({"<script>"+
            "select count(*) from gongShangNianJian g where g.zuoZhangShenBaoId = #{zuoZhangShenBaoId} AND g.xianShiZhuangTai = 1"+
            "<if test=\" companyName != null and companyName != ''\">" +
            " and g.companyName LIKE CONCAT ('%',#{companyName},'%') " +
            "</if>" +
            "<if test=\" suoShuNainDu != null and suoShuNainDu != ''\">" +
            " and g.suoShuNainDu = #{suoShuNainDu} " +
            "</if>" +
            "</script>"}
    )
    Integer selectYiGongShangNianJiancount(Integer zuoZhangShenBaoId,String companyName,String suoShuNainDu);

    /**
     * 查询未年检客户
     * 桑满 20210605
     * @return
     */
    @Select({"<script>"+
            "SELECT * FROM ZuoZhangShenBao z WHERE z.zuoZhangShenBaoId NOT IN (SELECT g.zuoZhangShenBaoId FROM gongShangNianJian g WHERE g.jiGouId = #{jiGouId} AND g.xianShiZhuangTai = 1) AND z.xianShiZhuangTai = 0 AND fuWuZhuangTai = #{fuWuZhuangTai} AND z.zuoZhangShenBaoId = #{zuoZhangShenBaoId}"+
            "<if test=\" companyName != null and companyName != ''\">" +
            " and companyName LIKE CONCAT ('%',#{companyName},'%') " +
            "</if>" +
            " ORDER BY createTime DESC LIMIT #{pages},#{limit}"+
            "</script>"})
    List<Map<String,Object>> selectWeiNianJian(Integer zuoZhangShenBaoId,String companyName,Integer fuWuZhuangTai, Integer pages,Integer limit);

    /**
     * 未年检公司数据总条数，用于分页
     * 桑满20210605
     * @param companyName
     * @param fuWuZhuangTai
     * @return
     */
    @Select({"<script>"+
            "SELECT count(*) FROM ZuoZhangShenBao z WHERE z.zuoZhangShenBaoId NOT IN (SELECT g.zuoZhangShenBaoId FROM gongShangNianJian g WHERE g.jiGouId = #{jiGouId} AND g.xianShiZhuangTai = 1) AND z.xianShiZhuangTai = 0 AND fuWuZhuangTai = #{fuWuZhuangTai} AND z.zuoZhangShenBaoId = #{zuoZhangShenBaoId}"+
            "<if test=\" companyName != null and companyName != ''\">" +
            " and companyName LIKE CONCAT ('%',#{companyName},'%') " +
            "</if>" +
            "</script>"})
    Integer selectWeiGongShangNianJiancount(Integer zuoZhangShenBaoId,String companyName,Integer fuWuZhuangTai);
}
